package com.heaven.dao;

import com.google.common.collect.Lists;
import com.heaven.Student;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;

@Component
public class QueryEntityDAO extends BaseDAO{
    public void insertInfo(){
        for(int i=2000;i<4000;i++){
            String name = "xc"+i;
            String stuno = "2018"+i;
            String sql = "insert into info(name, stuno) values('"+name+"', '"+stuno+"')";
            this.jdbcTemplate.update(sql);
        }
    }
    public void queryInfo(List<Integer> ids){
        String sql = "select * from info where id = %d";
        for(int id : ids){
            Map map = this.jdbcTemplate.queryForMap(String.format(sql, id));
            System.out.println(map.get("id")+" "+map.get("name")+"  "+map.get("stuno"));
        }
    }
    public List<Student> queryInfoList(List<Integer> ids) {
        List<Student> list = Lists.newLinkedList();
        String sql = "select * from info where id = %d";
        for(int id : ids){
            Map map = this.jdbcTemplate.queryForMap(String.format(sql, id));
            Student stu = new Student(Integer.parseInt(map.get("id").toString()), map.get("name").toString(), map.get("stuno").toString());
            list.add(stu);
        }
        return list;
    }

}
